//package com.zy.oauth.shiro;
//
//import com.zy.oauth.dto.AccountDto;
//import com.zy.oauth.service.AccountService;
//import org.apache.shiro.authc.*;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.springframework.beans.factory.annotation.Autowired;
//
//public class LoginRealm extends AuthorizingRealm {
//
//    public LoginRealm(String name) {
//        setName(name);
//    }
//
//    // 获取user相关信息的service类
//    @Autowired
//    private AccountService userLoginService;
//
//    // supports方法必须重写，这是shiro处理流程中的一部分，他会通过此方法判断realm是否匹配的正确
//    @Override
//    public boolean supports(AuthenticationToken token) {
//        return token instanceof LoginDataAutoToken;
//    }
//
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//        return null;
//    }
//
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException {
//        LoginDataAutoToken token = (LoginDataAutoToken) auth;
//        serviceLog.info(token.getUsername() + "password auth start...");
//        AccountDto user = (AccountDto) userLoginService.getUserByName(token.getUsername()).get(0);
//        if (user == null) throw new UnknownAccountException();
//        Object credentials = user.getPassword();
//        // save username and role to Attribute
//        ServletUtils.userNameRoleTo.accept(user.getUsername(), (int) user.getUserType());
//        return new SimpleAuthenticationInfo(user, credentials, super.getName());
//    }
//
//}
